<?php

namespace App\Models;

class OrderGoodsModel extends RbhBaseModel
{
    protected $table = 'df_order_goods';

    protected $guarded = [];

    /**
     * @param $orderNo
     * @param $goods
     * @param $supply
     * @return mixed
     */
    public static function createOrderGoods($orderNo, $goods, $supply): mixed
    {
        if ($goods && !empty($goods['goods_num'])) {
            return OrderGoodsModel::create([
                'order_no'      => $orderNo,
                'goods_id'      => $goods['goods_id'] ?: 0,
                'goods_sn'      => $goods['goods_sn'] ?: '',
                'goods_num'     => $goods['goods_num'],
                'thumbnail'     => $goods['thumbnail'] ?: '',
                'sid'           => $goods['sid'] ?: 0,
                'goods_name'    => $goods['goods_name'] ?: '',
                'sname'         => $supply ? $supply->CName: '',
                'color'         => $goods['color'] ?: '',
                'size'          => $goods['size'] ?: '',
                'weight'        => $goods['weight'] ?: 0,
                'price'         => $goods['price'] ?: 0,
                'building'      => $supply ? $supply->building : '',
                'floor'         => $supply ? $supply->floor : '',
                'room'          => $supply ? $supply->room : '',
            ]);
        }
    }
}
